<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Users_Users extends Controller_Template {

	public $template = 'template';
	private $page;
	private $uri;
	private $index;

	public function before()
	{
		parent::before();

		// Set the language
		I18n::$lang = Cookie::get('lang', 'ru-ru');

		$this->template->uri = 'admin/'.$this->request->controller.'/'.$this->request->action;
		$this->page = Page::findByLink($this->template->uri);

		$this->template->title = $this->page->title;
		$this->template->keywords = $this->page->keywords;
		$this->template->description = $this->page->description;

		$this->index = Route::get('admin/users');
	}

	public function action_index()
	{
		$this->template->content = View::factory('users/index')
			->set('users', User::findAll());

		$this->page = Page::findByParent($this->template->uri);
		$this->template->bind('breadcrumb', $breadcrumb);
		
		$breadcrumb = array();
		$breadcrumb[$this->index->uri(array('page' => NULL))] = $this->page->title;
		$breadcrumb[] = $this->template->title;
	}

	public function action_profile($id)
	{
		$this->template->content = View::factory('users/profile')
			->set('user', User::findOne($id));

		$this->page = Page::findByParent($this->template->uri);
		$this->template->bind('breadcrumb', $breadcrumb);
		$breadcrumb = array();
		$breadcrumb[$this->index->uri(array('page' => NULL))] = $this->page->title;
		$breadcrumb[] = $this->template->title.''.;
	}

	public function action_edit($id)
	{
		$this->template->content = View::factory('users/index')
			->set('users', User::findOne($id));

		$this->template->bind('breadcrumb', $breadcrumb);
	}

	public function after()
	{
		$this->template->styles = array(
			'public/css/admin.css'  => 'screen',
		);

		// Add scripts
		$this->template->scripts = array(
			"public/js/jquery.min.js",
			"public/js/jquery.cookie.js",
			"public/js/admin.js",
		);

		debug::all();
		parent::after();
	}

} // End Welcome